from django.db import models
from pets.models import Pet


class GeneticTest(models.Model):
    pet = models.ForeignKey(Pet, on_delete=models.CASCADE, related_name='genetic_tests')
    test_date = models.DateField()
    lab = models.CharField(max_length=100)
    test_type = models.CharField(max_length=100)
    raw_data = models.FileField(upload_to='genetics/raw_data/')
    report = models.FileField(upload_to='genetics/reports/')


class GeneticMarker(models.Model):
    test = models.ForeignKey(GeneticTest, on_delete=models.CASCADE, related_name='markers')
    marker_name = models.CharField(max_length=100)
    genotype = models.CharField(max_length=50)
    significance = models.TextField(blank=True)

    RISK_LEVELS = [
        ('L', 'Low Risk'),
        ('M', 'Medium Risk'),
        ('H', 'High Risk'),
    ]
    risk_level = models.CharField(max_length=1, choices=RISK_LEVELS, blank=True)


class BreedAnalysis(models.Model):
    test = models.OneToOneField(GeneticTest, on_delete=models.CASCADE, related_name='breed_analysis')
    primary_breed = models.CharField(max_length=100)
    primary_percentage = models.FloatField()
    secondary_breeds = models.JSONField(default=list, help_text="List of dictionaries with breed and percentage")
    breed_mix = models.JSONField(default=dict, help_text="Detailed breed composition")